using System;
using UnityEngine;

public class DataModel<T> : BaseBindModel
{
    private T value;
    private Action updateAction;

    public DataModel(T t)
    {
        Set(t);
    }

    override public void Bind(Action action)
    {
        updateAction = action;
        Update();
    }

    public void Update()
    {
        try
        {
            if (updateAction != null)
            {
                updateAction();
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e.Message);
        }
    }

    public void Set(T t)
    {
        value = t;
        Update();
    }

    public T Get()
    {
        return value;
    }
}
